/**
 * 资源加载
 */
class LoadAsync
{
	/**
	 * 加载单个资源
	 * @param  {string} resName
	 * @param  {any} compFunc
	 * @param  {any} thisObj
	 * @returns void
	 */
	public load(resName: string, compFunc: any, thisObj: any): void
	{
		let res = RES.getRes(resName);
		if (res)
		{
			if (compFunc && thisObj)
			{
				compFunc.apply(thisObj, [res, resName]);
			}
		} 
		else
		{
			// console.log("LoadAsync.load url: " + resName);			
			RES.getResAsync(resName, compFunc, thisObj);
		}
	}

	/**
	 * 加载资源数组
	 * @param  {Array<string>} resList
	 * @param  {Function} compFunc
	 * @param  {any} thisObj
	 * @returns void
	 */
	public loadList(resList: Array<string>, compFunc: Function, thisObj: any): void
	{
		if (!resList || resList.length <= 0)
		{
			return;
		}

		// console.log("LoadAsync.loadList: <" + resList.join(",") + ">");


		let idx = 0;
		let len = resList.length;
		let func = function ()
		{
			if (idx < resList.length)
			{
				let resName = resList[idx];

				idx += 1;

				let res = RES.getRes(resName);
				if (res)
				{
					func();
				} else
				{
					// console.log("LoadAsync.loadList.load: " + resName);					
					RES.getResAsync(resName, func, this);
				}
			} else
			{
				if (compFunc && thisObj)
				{
					compFunc.apply(thisObj);
				}
			}
		}

		func();
	}

	private static _instance: LoadAsync;
	public static it(): LoadAsync
	{
		if (!this._instance)
			this._instance = new LoadAsync();

		return this._instance;
	}
}